const getGatewayModel = PolygonNodeModel => {
  class GatewayModel extends PolygonNodeModel {
    static extendKey = 'GatewayModel'
    constructor(data, graphModel) {
      super(data, graphModel)
      this.points = [
        [25, 0],
        [50, 25],
        [25, 50],
        [0, 25],
      ]
    }
  }
  return GatewayModel
}

const getGatewayNode = (PolygonNode, h) => {
  class GatewayNode extends PolygonNode {
    static extendKey = 'GatewayNode'
    getShape() {
      const attributes = super.getAttributes()
      const { x, y, fill, stroke, strokeWidth, width, height, points } = attributes
      return h(
        'g',
        {
          transform: `matrix(1 0 0 1 ${x - width / 2} ${y - height / 2})`,
        },
        h('polygon', {
          fill,
          x,
          y,
          stroke,
          strokeWidth,
          points,
        })
      )
    }
  }
  return GatewayNode
}

export const registerGatewayNode = ({ PolygonNode, PolygonNodeModel, h }) => ({
  model: getGatewayModel(PolygonNodeModel),
  view: getGatewayNode(PolygonNode, h),
})
